home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / Files / Education / M / MathPad 2.15 / MathPad 2.1 / MathPad 2.1.rsrc / TEXT_128.txt < prev    next >
Encoding:
Text File  |  1993-10-06  |  4.1 KB  |  108 lines

  1. ~                       MathPad 2.1
  2.  
  3. MathPad may be used as a calculator simply by typing in the numbers and operators. When the ENTER key is hit, each line is evaluated and the results are inserted into the text.   Variables and functions can be defined. Results can be plotted or tabulated.  Command period can be used to stop evaluation.
  4. ~
  5. ----------------------- Examples:
  6. 21*(3+4)/2.4:61.2
  7.  
  8. 2 +     -- expressions are continued if the line ends with an operator
  9. 3*4:14.0
  10.  
  11. #+5:19.0;    -- # may be used to access the previous result
  12.  
  13. ------- variables and functions
  14. -- calculate a trajectory for initial velocity V, angle Theta.
  15. Vx=V*cos(Theta)
  16. Vy=V*sin(Theta) when Theta > 0 and Theta < 180, 0 otherwise
  17. altitude(t)=Vy*t-(g/2)*t^2
  18. impact_time=2*(Vy/g)
  19. apogee=(Vy^2)/(2*g);   range=Vx*impact_time
  20.  
  21. g=9.8; V=100;  Theta=75
  22.  
  23. range:510.2;    apogee:476.0
  24.  
  25. ------- plotting
  26. plot altitude(X)
  27. Xmin=0; Xmax=impact_time
  28. label apogee:476.0
  29.  
  30. ------- summation
  31. series(n) = sum(2*k-1,k,1,n)
  32. series(9):81.0
  33.  
  34. ------- recursion
  35. fact(n) = 1 when n ‚â§ 0, fact(n-1)*n
  36. fact(50):3.0e+64
  37.  
  38. ------- arrays
  39. A={10,20,30}      -- Defines a 3 element array.
  40. A[2]:20.0;     -- Accesses the 2nd element. Index values start at 1.
  41. B={A,{40,50,60},A+1}   --Multidimensional array.
  42. B:{{10.0,20.0,30.0},{40.0,50.0,60.0},{11.0,21.0,31.0}}
  43. B[1]:{10.0,20.0,30.0}
  44. B[1][2]:20.0
  45. B[1,2]:20.0;   -- Both forms of indexing are allowed
  46. A[2:3]:{20.0,30.0};    -- [lo:hi] selects a sub array.
  47. A[:2]:{10.0,20.0};     -- lo and/or hi may be omitted.
  48.  
  49. Q[i]=i*11  --Arrays can be defined in terms of their index values.
  50. Q[2]:22.0
  51. -- dim[] can be used to set the number of elements
  52. I[i,j] = 1 when i=j, 0   dim[3,3]
  53. I:{{1.0,0.0,0.0},{0.0,1.0,0.0},{0.0,0.0,1.0}}
  54.  
  55. --Arrays may be used freely in expressions. Operations are performed on each element.
  56. A+Q:{21.0,42.0,63.0}
  57. 2+A:{12.0,22.0,32.0}
  58. log(A):{1.0,1.3,1.5}
  59. A*Q:{110.0,440.0,990.0}; --Note: this is not matrix multiply
  60. Q[A]:? A[?];             --Arrays may not be used as index values.
  61.  
  62. --Functions can use index values
  63. skip(zz,by)[i] = zz[i*by] dim[count(zz)/by]
  64. skip(A,3):{30.0}
  65. skip(Q,2):{22.0,44.0,66.0,...}
  66. multiply(A,B)[i,j] = sum(A[i,k]*B[k,j],k,1,count(B)) dim
  67.              [count(A),count(B[1])]
  68. multiply({A},I):{{10.0,20.0,30.0}}
  69.  
  70. --Built-in functions for arrays
  71. count(A):3.0;  -- count() returns the number of array elements
  72.  count(B):3.0;  -- elements in 1st dimension
  73.  count(42):0.0; -- scalar
  74.  count(Q):?;    -- infinite array
  75. det(B):580.0;  -- calculates the determinant of a square matrix
  76. --read("filename") returns an array of values read from the named file.
  77. --write("filename",array)  writes the elements of the array to the named file.
  78.  
  79. --The plot command can also plot 1D or 2D arrays.
  80. --For 1D {y1,y2,y3...} the element values are used for y. X is stepped from Xmin to Xmax as usual. To connect the points, use "plotline" instead of "plot".
  81. -- 2D arrays can be given in 3 forms:
  82.  -- array of x,y pairs  {{x1,y1},{x2,y2},{x3,y3},...}
  83.  -- a pair of arrays    {{x1,x2,...},{y1,y2,...}}
  84.  -- a pair of functions {fx(X),fy(X)}
  85. -- For 2D arrays both x and y are taken from the array. X is stepped from 0 to 1.0 and can be used for parametric equations:
  86.  
  87. deg=X*360; Xsteps=36      -- run deg from 0 to 360 in 10¬∞ steps
  88. x(angle)=5*cos(angle)+10  -- arbitrary scale to fit on existing plot
  89. y(angle)=100*sin(angle)+200
  90. plot {x(deg),y(deg)}
  91.  
  92. --------- The image command can display 2D arrays
  93. img[i,j]=(i-10)^2-5*j^2 dim[20,20]
  94. image img
  95. Zmax=95; Zmin=-500
  96.  
  97. --------- assignments
  98. -- The assignment operator := evaluates the right hand side expression and replaces any previous value of the left hand variable with the result. Accessing the variable gives its current value.
  99. -- Assignments can only be done to global variables.
  100. -- Finite arrays may be assigned. Individual elements may not.
  101. -- The result of the := operation itself is always unknown. If you wish to access the result you must use the variable name. This is done so that multiple assignments can be performed using expression lists.
  102.  
  103. --------- iteration
  104. -- The 'while' operator can be used to evaluate some expression repeatedly.
  105.  
  106. factorial(n)= i:=1,k:=1,(k:=k*i,i:=i+1) while i<n, k
  107. factorial(400):1.6e+866
  108.